import regeneratorRuntime from '../../lib/runtime/runtime';
import { request } from "../../request/index.js";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs:[
            {
                id:0,
                value:"全部订单",
                isActive:true
            },
            {
                id:1,
                value:"待付款",
                isActive:false
            }, {
                id:2,
                value:"待发货",
                isActive:false
            }, 
            {
                id:3,
                value:"退货/退款",
                isActive:false
            }
        ],
    },
    handletabsItemChange(e){
        //1.获取被点击的索引
        const {index}=e.detail;
       this.changeTitleByIndex(index);
       this.getOrders(index+1);
    },
    onShow(options){
        // const token = wx.getStorageSync('token');
        // if(!token){
        //     wx.navigateTo({
        //       url: '/pages/auth/auth',
        //     })
        //     return;
        // }
        let pages=getCurrentPages();
        let currentPage=pages[pages.length-1];
        const {type}=currentPage.options;
        this.changeTitleByIndex(type-1);
        this.getOrders(type)
    },
    /* 获取订单列表的方法 */
    async getOrders(type){
        const res=await request({url:"/my/orders/all",data:{type}});
        console.log(res);
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
      /* 根据标题索引来激活选中 */
      changeTitleByIndex(index){
        let {tabs}=this.data;
        tabs.forEach((v,i) =>i===index?v.isActive=true:v.isActive=false);
        this.setData({
            tabs
        })
    },
})